const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function(app) {
    app.use(
      createProxyMiddleware('/api1', { //api1 转发路由键(所有带有/api1前缀的请求都会转发给5000)
        target: 'http://localhost:5000', // 代理服务器转发的目标地址
        pathRewrite: {'^/api1': ''}, //去除请求前缀，保证交给后台服务器的是正常请求地址(必须配置)
        changeOrigin: true, //控制服务器接收到的请求头中host字段的值
      }),
      createProxyMiddleware('/api2', {
        target: 'http://localhost:5001',
        pathRewrite: {'^/api2': ''}, 
        changeOrigin: true,
      })
    );
  };